package com.umeng.soexample.mvp.persenter;

import android.util.Log;

import com.umeng.lib_core.mvp.presenter.BasePresenter;
import com.umeng.soexample.bean.HomeMenuEntity;
import com.umeng.soexample.mvp.contract.ClassifyFragmentContract;

import javax.inject.Inject;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class ClassifyFragmentPresenter extends BasePresenter<ClassifyFragmentContract.ClassiftFragmentIView, ClassifyFragmentContract.ClassiftFragmentIModel> {
    @Inject
    public ClassifyFragmentPresenter(ClassifyFragmentContract.ClassiftFragmentIView classiftFragmentIView, ClassifyFragmentContract.ClassiftFragmentIModel classiftFragmentIModel) {
        super(classiftFragmentIView, classiftFragmentIModel);
    }

    //发起顶部选项网络请求
    public void requestMenu(){
        m.requestMenu().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<HomeMenuEntity>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        disposable.add(d);
                    }

                    @Override
                    public void onNext(HomeMenuEntity homeMenuEntity) {
                        v.menuSuccess(homeMenuEntity);
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("TT", "onError: " + e.toString() );
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
